package cate.game.play.skill.passive.exp;

import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.skill.FighterCD;
import cate.game.play.skill.passive.PassiveHandler;
import easy.java.struct.ref.DoubleRef;

/**
 * 当友方目标受到致死伤害时，减少自身15%最大生命值，为友方附加一个[免疫伤害]，可免疫1次伤害，自身生命值低于30%无法触发，冷却4回合
 */
public class 生死相护PH extends PassiveHandler {

	private double 扣除血量;

	private int 展示buff;

	private double 检测血量;

	private int 冷却回合;

	//扣除血量=1500&展示buff=？？&检测血量=3000&冷却回合=4
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		扣除血量 = args.getWDouble("扣除血量", 0d);
		展示buff = args.getInt("展示buff", 0);
		检测血量 = args.getWDouble("检测血量", 0d);
		冷却回合 = args.getInt("冷却回合", 0);
	}

	private int lastSettleRound;


	@Override
	public boolean adjustFriendDeadlyDamage(ActionCtx action, Fighter actor, Fighter target, int reason, DoubleRef doubleRef) {
		if (FighterCD.inCD(lastSettleRound, 冷却回合, action.getRound().index)) {
			return false;
		}
		if (skill.owner.attr.total().hpCurRate() < 检测血量) {
			return false;
		}
		lastSettleRound = action.getRound().index;
		doubleRef.v = 0;
		skill.owner.attr.passiveHurt(action, actor, skill.owner.attr.total().hpTotal() * 扣除血量);
		target.buff.tryAddByTid(action, skill.owner, 展示buff);
		return true;
	}
}
